******MICROCREDIT OUTCOMES (TABLE 2 and ONLINE APPENDIX TABLE XX)********

set more off
clear all 
clear matrix
capture log close

adopath + "$main/DoFiles"																		


local seed = 999
local reps = 5000


//--> DATA: FA SURVEY OUTCOMES
	*********************************************************************************************************************************************************


		use "$data/fASVY.dta", clear
		
		//--> CONSTRUCT MOTIVATION VARAIBLES 
			*********************************************************************************************************************************************************

		
			//--> DUMMY VARIABLE INDICATING RESPONSE "I FEEL LIKE I CAN REALLY HELP PEOPLE"
				****************************************
				
					g job_like_help = name_thing_likemost_nrsp==4 
					g fjob_like_help = fname_thing_likemost_nrsp==4

			//--> MOTIVATION INDEX
				****************************************

					egen motivation_index = rowmean(fjob_like_help fidentify_mission fwork_important)
					
//--> DATA: FA TREATMENT STATUS 
	*********************************************************************************************************************************************************
	
		sort fw_code
		merge fw_code using "$data/FWHR.dta"
		drop _m					
					
		
		//--> REGION DUMMIES
				tab region, gen(r)
				
		//--> SELECTION INTO FOLLOWUP SURVEY 
		
				g endline= 1 if fname_thing_likemost_nrsp!=.
				replace endline= 0 if endline==.
				

//--> OUTPUT: TABLE 5 (MOTIVATION OUTCOMES: 3 DUMMIES AND INDEX)	
	*********************************************************************************************************************************************************
	
	
	local mot_var fidentify_mission fwork_important fjob_like_help motivation_index
	
		//--> REGRESSION OUTPUT (FOR ESTIMATED COEEFICIENTS ONLY)
			****************************************	
			
				reg endline r1 r2 r3 treat_credit treat_sm
				sum endline if treat==0
				local m = r(mean)
				outreg2 using "$output/table5 (coeff).xls", replace addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
				local replace
				foreach v in `mot_var' {
					reg `v' job_like_help r1 r2 r3 treat_credit treat_sm if endline==1
					sum `v' if treat==0 & endline==1
					local m = r(mean)
					outreg2 using "$output/table5 (coeff).xls", `replace' addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
					local replace
					}
					
		
		
		log using "$output/table5 (p-values)", replace	

			
		//--> CALCULATE WILDCLUSTER T-BOOTSTRAP P VALUES
			****************************************		
			
				//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL
				
						cgmwildboot endline r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')	
						foreach v in `mot_var' {
							cgmwildboot `v' job_like_help r1 r2 r3 treat_credit treat_sm if endline==1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
							}
						
				//--> CREDIT VS. SOCIAL
				
						g x1 = treat_credit + treat_sm
						g test1 = treat_credit //RELEVANT VAR FOR F TEST
							
						cgmwildboot endline r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 	
						foreach v in `mot_var' {
							cgmwildboot `v' job_like_help r1 r2 r3 test1 x1 if endline==1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
							}

							
		//--> CALCULATE RANDOMIZATION INFERENCE BASED P VALUES
			****************************************						
						
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL				
					
					randcmd((treat_credit treat_sm) reg endline treat_credit treat_sm r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') 
					foreach v in `mot_var' {
						randcmd((treat_credit treat_sm) reg `v' job_like_help treat_credit treat_sm r1 r2 r3 if endline==1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') 
						}
							
			//--> CREDIT VS. SOCIAL (F TEST)
			
					randcmd((treat_credit) reg endline treat_credit x1 r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
					foreach v in `mot_var' {
						randcmd((treat_credit) reg `v' job_like_help treat_credit x1 r1 r2 r3 if endline==1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
						}
			
	log close
	*********************************************************************************************************************************************************
						
						
